﻿using Blog.Model;
using Blog.Model.Dto.Memento;
using Microsoft.AspNetCore.Mvc;

namespace Blog.WebApi.Controllers
{
    [ApiController]
    [Route("api/[controller]/[action]")]
    public class MementoController : Controller
    {
        private IMementoService _MementoService;

        public MementoController(IMementoService mementoService)
        {
            _MementoService = mementoService;
        }

        /// <summary>
        /// 获取记忆碎片
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        [HttpGet]
        public ApiResult GetMementoList(ListParam param)
        {
            return _MementoService.MementoList(param);
        }

        /// <summary>
        /// 添加记忆碎片
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        [HttpPost]
        public ApiResult AddMemento(MementoAdd param)
        {
            return _MementoService.AddMemento(param);
        }

        /// <summary>
        /// 删除记忆碎片
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        [HttpPost]
        public ApiResult DelMemento(ListIds param)
        {
            if (param == null || param.ids.Any())
                return new ApiResult().Error("参数列表为空!");
            return _MementoService.DelMemento(param);
        }

        /// <summary>
        /// 编辑记忆碎片
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        [HttpPost]
        public ApiResult UpMemento(MementoUp param)
        {
            if (param == null || string.IsNullOrEmpty(param.Id))
                return new ApiResult().Error("参数列表为空!");
            return _MementoService.UpMemento(param);
        }
    }
}
